<template>
	<view class="old-diy-text component-diy" :style="boxStyle">
		<view class="top">
			<view class="title" :style="{color: componentData.titleColor}">{{componentData.title}}</view>
			<block v-if="componentData.viewMore">
				<view @click="toUrl">
					<view class="view-more" :style="moreTextColor"
						v-if="!componentData.viewMoreType || componentData.viewMoreType == 0">
						{{componentData.viewMoreText}}</view>
					<view class="view-more" :style="moreTextColor" v-else-if="componentData.viewMoreType == 1">
						{{componentData.viewMoreText}}
						<uni-icons type="arrowright" :color='componentData.moreBtnColor' size="12"></uni-icons>
					</view>
					<view class="view-more" v-else-if="componentData.viewMoreType == 2">
						<uni-icons type="arrowright" :color='componentData.moreBtnColor' size="12"></uni-icons>
					</view>
				</view>
			</block>
		</view>
		<div class="desc" v-if="componentData.desc" :style="{color: componentData.descColor}">
			{{componentData.desc}}
		</div>
	</view>
</template>

<script>
	export default {
		props: ['componentData'],
		data() {
			return {}
		},
		computed: {
			boxStyle() {
				let css = {
					'background-color': this.componentData.backgroundColor, //背景颜色
					'margin-top': this.componentData.marginTop + 'px', //上边距
					'margin-bottom': this.componentData.marginBottom + 'px', //下边距
					'margin-left': this.componentData.marginLR + 'px', //左边距
					'margin-right': this.componentData.marginLR + 'px', //右边距
					'border-radius': this.componentData.borderRadius + 'px',
				}
				return this.$joinStyle(css);
			},
			moreTextColor() {
				let css = {
					'color': this.componentData.moreTextColor,
				}
				return this.$joinStyle(css);
			},
		},
		methods: {
			toUrl() {
				const url = this.componentData.page.url;
				if (url) {
					uni.navigateTo({
						url: url
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.old-diy-text {
		background-color: #FFFFFF;
		padding: 14px;

		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex-wrap: wrap;
			overflow: hidden;

			.title {
				font-size: 16px;
				color: #323233;
			}

			.view-more {
				font-size: 12px;
				color: #969799;

				&.blue {
					color: #38F;
				}
			}
		}

		.desc {
			font-size: 12px;
			color: #969799;
			margin-top: 8px;
		}
	}
	
</style>
